<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <#include "include/_meta.html">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>

</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 信用分值列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container" id="creditList">
    <div class="text-c">
        手机号:
        <input type="text" class="input-text" style="width:250px" placeholder="输入手机号" id="mobile" name="">
        身份证号:
        <input type="text" class="input-text" style="width:250px" placeholder="输入身份证号 " id="idcard" name="">

        <button type="submit" class="btn btn-success" id="searchUsers" name="">
            <i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius">
                <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
            </a>
	<a href="javascript:;"  class="btn btn-primary radius" id="creditAdd">
        <i class="Hui-iconfont">&#xe600;</i> 添加客户</a>
        </span>

        <span class="r">共有数据：<strong id="pageTotal">54</strong> 条</span>
    </div>
    <table id="userListTable" class="table table-border table-bordered table-bg table-hover">
        <thead>
        <tr>
            <th scope="col" colspan="9">账户列表</th>
        </tr>
        <tr class="text-c">
            <th width="25"><input type="checkbox" name="useritem" value=""></th>
            <th style="display: none"></th>
            <th width="100">客户姓名</th>
            <th width="90">手机号</th>
            <th width="120">身份证号码</th>
            <th width="150">信用值</th>
            <th width="70" >信用值变化</th>
            <th width="130">变化原因</th>
            <th width="70">操作</th>


        </tr>
        </thead>
        <tbody>
        <tr class="text-c" v-for="credit in info.list">
            <td><input type="checkbox" name="useritem" :value="credit.cid"></td>
            <td style="display: none">{{credit.cid}}</td>
            <td>{{credit.name}}</td>
            <td>{{credit.mobile}}</td>
            <td>{{credit.idcard}}</td>
            <td>{{credit.creditnum}}</td>
            <td>{{credit.creditchange}}</td>
            <td>{{credit.changereason}}</td>
            <td>
                <a href="#" @click="editEvent(credit.cid)">编辑</a>
                <a href="#" @click="delEvent(credit.cid)">删除</a>
            </td>
        </tr>
        </tbody>
    </table>
    <div class="pagenav" id="pagenav"></div>
</div>

<#include "include/_footer.html">

<script type="text/javascript">
    var creditList=new Vue({
        el:'#creditList',
        data:{
            info:{}
        }
    });

    var getCreditList = function (curr) {
        $.ajax({
            url:"/credit",
            data:{
                pageSize:8,
                curr:curr || 1,
                mobile:$("#mobile").val(),
                idcard:$("#idcard").val()
            },
            dataType:"json",
            type:"GET",
            success:function (info) {
                creditList.info=info;
                laypage({
                    cont:"pagenav",
                    pages:info.pages,
                    skin:"#DB7023",
                    first:"首页",
                    last:"最后一页",
                    curr:curr || 1,
                    jump:function (obj,first) {
                        if (!first){
                            getCreditList(obj.curr);
                        }
                    }

                });
            }
        });
    }
    getCreditList();

    $("#searchUsers").click(function () {
        getCreditList();
    })


    /*添加用户信息*/
   $("#creditAdd").on("click",function () {
        layer.open({
            type:2,
            title:"编辑用户",
            fix:false,
            maxmin:true,
            shadeClose:true,
            area:['800px','400px'],
            content:"/credit-add",
            end:function () {
                getCreditList();
            }
        });
    });


    /*修改客户信息*/
    var editEvent=function (cid) {
        layer.open({
            type:2,
            title:"编辑用户",
            fix:false,
            maxmin:true,
            shadeClose:true,
            area:['800px','600px'],
            content:"/creditPage?cid="+cid,
            end:function () {
                getCreditList();
            }
        })
    }

    /*根据ID删除信用值信息*/
    var delEvent=function (cid) {
        //删除确认框
        layer.confirm('确认删除？',{
            btn:['是','否']
        },function () {
            $.ajax({
                type:"post",
                dataType:"json",
                url:"/creditDel",
                data:{
                    cid:cid
                },
                success:function (msg) {
                    getCreditList();
                    layer.msg("已经删除",{icon:6});
                }
            });
        },function () {

        });
    }

    //批量删除
    var datadel=function () {
        //判断是否选中复选框
        var checkedNum=$("input[name='useritem']:checked").length;
        if (checkedNum==0){
            layer.msg('请选中要删除的列表项',{icon:5});
            return;
        }
        //获取复选框的值
        var checkedVal="";
        $("input[name='useritem']:checked").each(function () {
            checkedVal+=$(this).val()+",";
        });

        var itemsTipStr="这条记录";
        if (checkedNum>1){
            itemsTipStr="这些选项";
        }
        layer.confirm('确认要删除'+itemsTipStr+'吗?',function () {
            $.ajax({
                type:"POST",
                url:"/deleteCredit",
                dataType:"json",
                data:"creditCid="+checkedVal,
                success:function (msg) {
                    getCreditList();
                    layer.msg('删除成功',{icon:5,time:1000});
                }
            })
        })
    }

</script>
</body>